package com.group.project.hrms.service.impl;

import com.group.project.hrms.entity.ContactArchivesWorking;
import com.group.project.hrms.mapper.ContactArchivesWorkingMapper;
import com.group.project.hrms.service.IContactArchivesWorkingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class ContactArchivesWorkingService implements IContactArchivesWorkingService {

    @Autowired
    private ContactArchivesWorkingMapper contactArchivesWorkingMapper;

    @Override
    public int insertContactArchivesWorking(ContactArchivesWorking contactArchivesWorking) {
        return contactArchivesWorkingMapper.insert(contactArchivesWorking);
    }

    @Override
    public int deleteContactArchivesWorking(ContactArchivesWorking contactArchivesWorking) {
        return contactArchivesWorkingMapper.deleteByPrimaryKey(contactArchivesWorking);
    }

    @Override
    public int updateContactArchivesWorking(ContactArchivesWorking contactArchivesWorking) {
        return contactArchivesWorkingMapper.updateByPrimaryKey(contactArchivesWorking);
    }

    @Override
    public ContactArchivesWorking selectOneContactArchivesWorking(ContactArchivesWorking contactArchivesWorking) {
        return contactArchivesWorkingMapper.selectByPrimaryKey(contactArchivesWorking);
    }

    @Override
    public ContactArchivesWorking selectOneContactArchivesWorkingByContactID(String contactID) {
        Example example = new Example(ContactArchivesWorking.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("contactId" , contactID);
        return contactArchivesWorkingMapper.selectOneByExample(example);
    }

    @Override
    public List<ContactArchivesWorking> selectAllContactArchivesWorkingByStaffStatus(int status) {
        Example example = new Example(ContactArchivesWorking.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orEqualTo("staffStatus" , status);
        return contactArchivesWorkingMapper.selectByExample(example);
    }

    @Override
    public List<ContactArchivesWorking> selectContactArchivesWorkingsByLeaveMonth(String leaveMonth) {
        Example example = new Example(ContactArchivesWorking.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orLike("leaveActualDate", "%" + leaveMonth + "%");
        return contactArchivesWorkingMapper.selectByExample(example);
    }

    @Override
    public List<ContactArchivesWorking> selectContactArchivesWorkingsByJoinedMonth(String joinedMonth) {
        Example example = new Example(ContactArchivesWorking.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orLike("onboardActualDate", "%" + joinedMonth + "%");
        return contactArchivesWorkingMapper.selectByExample(example);
    }

    @Override
    public List<ContactArchivesWorking> selectAllContactArchivesWorking() {
        return contactArchivesWorkingMapper.selectAll();
    }
}
